// pages/forgetPassword/forgetPasswordNext/forgetPasswordNext.js
var util = require('../../../utils/util.js')
var app = getApp()
var rootUrl = app.globalData.rootDocment
var imgPublicUrl = rootUrl + 'Public/Home/images/'
var flag = false
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  passWord: "",
	  confirmPassword: "",
	  phonenumber:null,
	  submitload: false,	//提交Loading状态
     imageArr: {
      forgetPasswordTwoImg: imgPublicUrl + 'forgetPasswordTwoImg.png'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  //接收参数
	  this.setData({ phonenumber:options.PhoneNum})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
	app.publicchangenavigate()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
	return app.globalshare();
  },
  //密码
  passWordInput: function (e) {
	  this.setData({
		  passWord: e.detail.value,
	  })
  },
  //确认密码
  confirmPasswordInput: function (e) {
	  this.setData({
		  confirmPassword: e.detail.value,
	  })
  },
  //点击提交按钮
  formSubmit: function (e) {
	  var warn = "";
	  var that = this;

	  if (e.detail.value.passWord == '') {
		  warn = "请输入新密码";
    } else if ((/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(e.detail.value.passWord))) {
      warn = "密码由字母和数字组成，至少6位";
    } else if (e.detail.value.confirmPassword == '') {
		  warn = "请再次输入新密码";
	  } else if (e.detail.value.passWord != e.detail.value.confirmPassword) {
		  warn = "两次密码不一致";
	  } else {
		  flag = true;
	  }
	  //执行结果
	  if (flag) {
		  //开启加载
		  that.setData({ submitload: true })

		  var sessvalue = wx.getStorageSync('sessionid')
		  //整合上传数据
		  e.detail.value.openids = sessvalue
		  e.detail.value.telPhoneNumber = this.data.phonenumber
		  //提交给服务端注册信息
		  util.AJAX('Home/Login/upUserPwd', e.detail.value, function (res) { //方法体
			  //关闭加载
			  that.setData({ submitload: false })

			  if (res.data.StatusCode == 100) {  //成功
				  wx.showToast({
					  title: res.data.Msg,
					  icon: 'success',
					  duration: 2000
				  })

				  setTimeout(function () {
					  //关闭当前页面
					  wx.navigateBack()
				  }, 2000);
			  } else {	//失败
				  wx.showModal({
					  title: '提示',
					  content: res.data.Msg
				  })
			  }
		  }, 'POST')

	  } else {
		  wx.showModal({
			  title: '提示',
			  content: warn
		  })
	  }
  },

})